###########################################################################
# Happy Hare main configuration parameters
#
# Note that macro configuration is specifed separately in:
#   mmu_sequence.cfg - Customization of loading and unloading sequences
#   mmu_form_tip.cfg - Tuning of standalone tip forming
#   mmu_cut_tip.cfg  - Tuning of toolhead based tip cutting
# Full details in https://github.com/moggieuk/Happy-Hare/tree/main/doc/configuration.md
#
[mmu]
happy_hare_version: 2.42	# Don't mess, used for upgrade detection
#
# The vendor and version config is important to define the capabilities of the MMU and basic CAD dimensions. These can
# all be overridden with the `cad` parameters detailed in the documentation but the vendor setting saves time.
#
# ERCF
# 1.1 original design, add "s" suffix for Sprigy, "b" for Binky, "t" for Triple-Decky
#     e.g. "1.1sb" for v1.1 with Springy mod and Binky encoder
#
# 2.0 new community ERCFv2, add "h" suffix for ThumperBlocks
#
# Tradrack
# 1.0 add "e" if using encoder is fitted
#
# Prusa
#  - Comming soon (use Other for now)
#
# Other
#  - Generic setup that will require further customization of `cad` parameters. See doc and section at the end
#
mmu_vendor: Other			# MMU family
mmu_version: 1			# MMU hardware version number (add mod suffix documented above)
mmu_num_gates: 2 			# Number of selector gates


# MMU Limits ---------------------------------------------------------------------------------------------------------------
#
# Define the physical limits of your MMU. These setings will be respected regardless of individual speed settings.
#
gear_max_velocity: 300			# Never to be exceeded gear velocity regardless of specific parameters
gear_max_accel: 500			# Never to be exceeded gear accelaration regardless of specific parameters
selector_max_velocity: 250		# Never to be exceeded selector velocity regardless of specific parameters
selector_max_accel: 100		# Never to be exceeded selector accelaration regardless of specific parameters


# Servo configuration  -----------------------------------------------------------------------------------------------------
#
# Angle of the servo in three named positions
#   up   = tool is selected and filament is allowed to freely move through gate
#   down = to grip filament
#   move = ready the servo for selector move (optional - defaults to up)
# V2.4 on: These positions are only for initial config they are replaced with calibrated servo positions in `mmu_vars.cfg`
#
# Note that leaving the servo active when down can stress the electronics and is not recommended with EASY-BRD or ERB board
# unless the 5v power supply has been improved and it is not necessary with standard ERCF builds
# Make sure your hardware is suitable for the job!
#
servo_up_angle: 0			# ERCF: MG90S: 30  ; SAVOX SH0255MG: 140 ; Tradrack: 145
servo_down_angle: 0			# ERCF: MG90S: 140 ; SAVOX SH0255MG: 30  ; Tradrack: 1
servo_move_angle: 0			# Optional angle used when selector is moved (defaults to up position)
servo_duration: 0.2			# Duration of PWM burst sent to servo (automatically turns off)
servo_dwell: 0.5			# Minimum time given to servo to complete movement prior to next move
servo_active_down: 0			# CAUTION: 1=Force servo to stay active when down, 0=Release after movement
#servo_buzz_gear_on_down: 3		# Whether to "buzz" the gear stepper on down to aid engagement


# Logging ------------------------------------------------------------------------------------------------------------------
#
# log_level & logfile_level can be set to one of (0 = essential, 1 = info, 2 = debug, 3 = trace, 4 = stepper moves)
# Generally you can keep console logging to a minimal whilst still sending debug output to the mmu.log file
# Increasing the console log level is only really useful during initial setup to save having to constantly open the log file
#
log_level: 1
log_file_level: 3			# Can also be set to -1 to disable log file completely
log_statistics: 1 			# 1 to log statistics on every toolchange (default), 0 to disable (but still recorded)
log_visual: 2				# 1 log visual representation of filament, 0 = disable
log_startup_status: 1			# Whether to log tool to gate status on startup, 1 = summary (default), 2 = full, 0 = disable


# Movement speeds ----------------------------------------------------------------------------------------------------------
#
# Long moves are faster than the small ones and used for the bulk of the bowden movement. Note that you can set two fast load
# speeds depending on whether MMU thinks it is pulling from the buffer or from the spool. It is often helpful to use a lower
# speed when pulling from the spool because more force is required to overcome friction and this prevents loosing steps.
# 100mm/s should be "quiet" with the NEMA14 motor or a NEMA17 pancake, but you can go lower for really low noise
# NOTE: Encoder cannot keep up much above 250mm/s so make sure `bowden_apply_correction` is off at very high speeds!
#
gear_from_buffer_speed: 160		# mm/s Normal speed when loading filament. Conservative is 100mm/s, Max around 300mm/s
gear_from_buffer_accel: 400		# Normal accelaration when loading filament
gear_from_spool_speed: 60		# mm/s Use (lower) speed when loading from a gate for the first time (i.e. pulling from spool)
gear_from_spool_accel: 100		# Accelaration when loading from spool
#
gear_short_move_speed: 60		# mm/s Speed when making short moves (like incremental retracts with encoder)
gear_short_move_accel: 400		# Usually the same as gear_from_buffer_accel (for short movements)
gear_short_move_threshold: 70		# Move distance that controls application of 'short_move' speed/accel
gear_homing_speed: 50			# mm/s Speed of gear stepper only homing moves (e.g. homing to gate or extruder)

# Speeds of extruder movement. The 'sync' speeds will be used when gear and extruder steppers are moving in sync
#
extruder_load_speed: 16			# mm/s speed of load move inside extruder from homing position to meltzone
extruder_unload_speed: 16		# mm/s speed of unload moves inside of extruder (very initial move from meltzone is 50% of this)
extruder_sync_load_speed: 18		# mm/s speed of synchronized extruder load moves
extruder_sync_unload_speed: 18		# mm/s speed of synchronized extruder unload moves
extruder_homing_speed: 20		# mm/s speed of extruder only homing moves (e.g. to toolhead sensor)

# Selector movement speeds. (Accelaration is defined by physical MMU limits set above and passed to selector stepper driver)
#
selector_move_speed: 200		# mm/s speed of selector movement (not touch)
selector_homing_speed: 60		# mm/s speed of initial selector homing move (not touch)
selector_touch_speed: 80		# mm/s speed of all touch selector moves (if stallguard configured)

# Selector touch (stallguard) operation. If stallguard is configured, then this can be used to switch on touch movement which
# can detect blocked filament path and try to recover automatically but it is more difficult to set up
#
selector_touch_enable: 1		# If selector touch operation configured this can be used to disable it 1=enabled, 0=disabled


# Gate loading/unloading ------------------------------------------------------------------------------------------------
#
# These setttings control the loading and unloading filament at the gate. The primary options are you use a endstop switch
# at the gate (ala TradRack) or an encoder (ERCF default).  You can even have both a gate sensor for loading/parking and still use
# the encoder for other move verification (see advanced 'gate_endstop_to_encoder' option).
# Note: the `encoder` method, due to the nature of its operation will overshoot a little. This is not a problem in practice
# because the overshoot will simply be compensated for in the subsequent fast bowden move.
# 
# Possible gate_homing_endtop names:
#   encoder  - Detect filament position using movement of the encoder
#   mmu_gate - Detect filament using a gate endstop if configured
#
gate_homing_endstop: mmu_gate		# Name of gate endstop, "encoder" forces use of encoder for parking
gate_homing_max: 70			# Maximum move distance to home to the gate (actual move distance for encoder parking)
gate_unload_buffer: 50			# Amount to reduce the fast unload so that filament doesn't overshoot when parking
gate_load_retries: 2			# Number of times MMU will attempt to grab the filament on initial load (max 5)
gate_parking_distance: 23 		# ADVANCED: Parking postion in the gate (distance back from gate endstop/encoder point)
gate_endstop_to_encoder: 0		# ADVANCED: Distance between gate endstop and encoder (IF both fitted. +ve if encoder after endstop)


# Bowden tube loading/unloading --------------------------------------------------------------------------------------------
#
# In addition to different bowden loading speeds for buffer and non-buffered filament it is possible to detect missed steps
# caused by "jerking" on a heavy spool. If bowden correction is enabled the driver with "believe" the encoder reading and
# make correction moves to bring the filament to within the 'bowden_allowable_load_delta' of the end of bowden position
# (this does require a reliable encoder and is not recommended for very high speed loading >200mm/s)
#
bowden_apply_correction: 0		# 1 to enable, 0 disabled (default) [Requires Encoder]
bowden_allowable_load_delta: 20.0	# How close in mm the correction moves will attempt to get to target [Requires Encoder]

# This test verifies the filament is free of extruder before the fast bowden movement to reduce possibility of grinding filament
bowden_pre_unload_test: 0		# 1 to check for bowden movement before full pull (slower), 0 don't check (faster) [Requires Encoder]

# ADVANCED: If pre-unload test is enabled, this controls the detection of successful bowden pre-unload test and represents the
# fraction of allowable mismatch between actual movement and that seen by encoder. Setting to 50% tolerance usually works well.
# Increasing will make test more tolerent. Value of 100% essentially disables error detection
#
bowden_pre_unload_error_tolerance: 50


# Extruder homing ---------------------------------------------------------------------------------------------------------
#
# Happy Hare needs a reference "homing point" close to the extruder from which to accurately complete the loading of the toolhead.
# This homing operation takes place after the fast bowden load and it is anticipated that that load operation will leave the
# filament just shy of the homing point. If using a toolhead sensor this initial extruder homing is unecessary (but can be forced)
# because the homing will occur inside the extruder for the optimum in accuracy.
#
# In addition to an entry sensor "mmu_extruder" it is possbile for Happy Hare to "feel" for the extruder gear entry by colliding
# with it. Because this method is not completely deterministic you might find have to find the sweetspot for your setup by adjusting
# the TMC current reduction. Also, touch (stallguard) sensing is possible to configure but unfortunately doesn't work well with
# some external mcu's. Note that reduced current during collision detection can also prevent unecessary filament griding
#
# Possible homing_endtop names:
#   collision      - Detect the collision with the extruder gear by monitoring encoder movement (Requires encoder)
#   mmu_gear_touch - Use touch detection when the gear stepper hits the extruder (Requires stallguard)
#   extruder       - If you have a "filament entry" endstop configured (Requires 'extruder' endstop)
#   none           - Don't attempt to home. Only possibiliy if lacking all sensor options (not recommended)
# Note: The homing_endstop will be ignored if a toolhead sensor is available unless `extruder_force_homing: 1`
#
extruder_homing_max: 200			# Maximum distance to advance in order to attempt to home the extruder
extruder_homing_endstop: extruder	# Filament homing method/endstop name (fallback if toolhead sensor available)
extruder_homing_current: 40		# % gear_stepper current (10%-100%) to use when homing to extruder homing (100 to disable)

# In the absence of a toolhead sensor Happy Hare will automatically default to extruder entrance detection regardless of
# this setting, however if you have a toolhead sensor you can still force the additional (unecessary) step of initially homing to
# extruder entrance then home to the toolhead sensor
#
extruder_force_homing: 1


# Default toolhead loading and unloading ----------------------------------------------------------------------------------
#
# It is possible to define highly customized loading and unloading sequences, however, unless you have a specialized setup
# it is probably easier to opt for the built-in toolhead loading and unloading sequence which already offers a high degree
# of customization. If you need even more control then edit the _MMU_LOAD_SEQUENCE and _MMU_UNLOAD_SEQUENCE macros in
# mmu_sequence.cfg - but be careful!
#
# An MMU must have a known point at the end of the bowden from which it can precisely load the extruder. Generally this will
# either be the extruder extrance (which is controlled with settings above) or by homing to toolhead sensor. If you have
# toolhead sensor it is past the extruder gear and the driver needs to know the max distance (from end of bowden move) to
# attempt homing
#
toolhead_homing_max: 40			# Maximum distance to advance in order to attempt to home to defined homing endstop

# IMPORTANT: These next three settings are based on the physical dimensions of your toolhead
# Once a homing position is determined, Happy Hare needs to know the final move distance to the nozzle. There is only one
# correct value for your setup - use 'toolhead_ooze_reduction' to control excessive oozing on load. See doc for table of
# proposed values for common configurations. E.g Revo Voron with CW2 extruder values are 72 & 62 respectively
#
toolhead_extruder_to_nozzle: 72		# Distance from extruder gears (entrance) to nozzle
toolhead_sensor_to_nozzle: 62		# Distance from toolhead sensor to nozzle (ignored if not fitted)
#toolhead_entry_to_extruder: 8		# Distance from extruder "entry" sensor to extruder gears (ignored if not fitted)

# TUNING: The is a tuning setting that should start at 0. It represents how much to reduce the extruder loading to prevent
# excessive ooze. It is important to tune this parameter and not the dimensions above which are shared by unload logic.
# If you experience blobs on your purge tower, increase this value. If you experience gaps, decrease this value. If gaps and
# already at 0 then perhaps the 'toolhead_extruder_to_nozzle' setting is incorrect
#
#toolhead_ooze_reduction: 0		# Reduction in extruder loading length to fine tune ooze (default: 0mm)

# Distance added to the extruder unload movement to ensure filament is free of extruder. This adds some degree of tolerance
# to slightly incorrect configuration or extruder slippage. However don't use as an excuse for incorrect toolhead settings
#
toolhead_unload_safety_margin: 10	# Extra movement saftey margin (default: 10mm)

# ADVANCED: Controls the detection of successful extruder load/unload movement and represents the fraction of allowable
# mismatch between actual movement and that seen by encoder. Setting to 100% tolerance effectively turns off checking.
# Some designs of extruder have a short move distance that may not be picked up by encoder and cause false errors. This allows
# masking of those errors. However the error often indicates that your extruder load speed is too high or the friction is too
# high on the filament and in that case masking the error is not a good idea. Try reducing friction and lowering speed first!
#
toolhead_move_error_tolerance: 60


# Tip forming -------------------------------------------------------------------------------------------------------------
#
# Tip forming responsibity is typically split between slicer (in-print) and standalone macro (not in-print). Whilst there is
# an option to choose for every toolchange, setting 'force_form_tip_standalone: 1' will always do the standalone sequence.
# Frankly it is usually recommended to disable tip forming in your slicer and to do exclusively in Happy Hare so tuning only
# has to be done in one place.
#
# When Happy Hare is asked to form a tip it will run the referenced macro. Two are reference examples are provided:
#   _MMU_FORM_TIP .. default tip forming similar to popular slicers like Superslicer and Prusaslicer
#   _MMU_CUT_TIP  .. for Filametrix (ERCFv2) style toolhead filament cutting system
#
# Often it is useful to increase the current for the (generally) rapid movement to ensure high torque and no skipped steps
#
# If opting for slicer tip forming you must configure where the slicer leaves the filament in the extruder since there
# is no way to determine this. This can be ignored if all tip forming is performed by Happy Hare
#
force_form_tip_standalone: 0		 # 0 = Default smart behavior, 1 = Always do standalone tip forming (TURN SLICER OFF!)
form_tip_macro: _MMU_FORM_TIP            # Name of macro to call to perform the tip forming (or cutting) operation
extruder_form_tip_current: 100		 # % of extruder current (100%-150%) to use when forming tip (100 to disable)
slicer_tip_park_pos: 0			 # This specifies the position of filament in extruder after slicer tip forming move


# Synchronized gear/extruder movement --------------------------------------------------------------------------------------
#
# This controls whether the extruder and gear steppers are synchronized during printing operations
# If you normally run with maxed out gear stepper current consider reducing it with 'sync_gear_current'
# If equipped with TMC drivers the current of the gear and extruder motors can be controlled to optimize performance.
# This can be useful to control gear stepper temperature when printing with synchronized motor
#
sync_to_extruder: 1			# Gear motor is synchronized to extruder during print
sync_gear_current: 50			# % of gear_stepper current (10%-100%) to use when syncing with extruder during print
sync_form_tip: 0			# Synchronize during standalone tip formation (initial part of unload)

# Optionally it is possible to leverage feedback for a "compression/expansion" sensor in the bowden path from MMU to extruder
# to ensure that the two motors are kept in sync as viewed by the filament (the signal feedback state can be binary supplied
# by one or two switches: -1 (expanded) and 1 (compressed) of proportional value between -1.0 and 1.0
# Requires [mmu_sensors] setting
#
#sync_feedback_enable: 0			# 0 = Turn off (even with fitted sensor), 1 = Turn on when printing
#sync_multiplier_high: 1.05		# Maximum factor to apply to gear stepper `rotation_distance`
#sync_multipler_low: 0.95		# Minimum factor to apply


# Filament Management Options --------------------------------------------------------------------------------------------
#
# - Clog detection is available when encoder is fitted and it can detect when filament is not moving and pause the print.
# - EndlessSpool feature allows detection of runout on one spool and the automatic mapping of tool to an alternative
#   gate (spool). Set to '1', this feature requires clog detection or gate sensor or pre-gate sensors. EndlessSpool
#   functionality can optionally be extended to attempt to load an empty gate with 'endless_spool_on_load'
# - Spoolman support will use the SpoolId configured with the gate to load filament details and color from spoolman.
#
enable_clog_detection: 2		# 0 = disable, 1 = static length clog detection, 2 = automatic length clog detection
enable_endless_spool: 1			# 0 = disable, 1 = enable endless spool
endless_spool_on_load: 0		# 0 = don't apply endless spool on load, 1 = run endless spool if gate is empty
endless_spool_final_eject: 50		# Extra unload distance on runout to prevent accidental reload
enable_spoolman: 0			# 0 = disable spoolman support,  1 = enable spoolman (requires spoolman setup)
#endless_spool_groups:			# Default EndlessSpool groups (see later in file)


# Turn on behavior -------------------------------------------------------------------------------------------------------
#
# MMU can auto-initialize based on previous persisted state. There are 5 levels with each level bringing in
# additional state information requiring progressively less inital setup. The higher level assume that you don't touch
# MMU while it is offline and it can come back to life exactly where it left off!  If you do touch it or get confused
# then issue an appropriate reset command (E.g. MMU_RESET) to get state back to the defaults.
# Enabling `startup_status` is recommended if you use persisted state at level 2 and above
# Levels: 0 = start fresh every time except calibration data (the former default behavior)
#         1 = restore persisted endless spool groups
#         2 = additionally restore persisted tool-to-gate mapping
#         3 = additionally restore persisted gate status (filament availability, material and color, spoolID) (default)
#         4 = additionally restore persisted tool, gate and filament position! (Recommended when MMU is working well)
#
persistence_level: 3


# Misc configurable, but fairly fixed values -----------------------------------------------------------------------------
#
extruder: extruder		# Name of the toolhead extruder that MMU is using
timeout_pause: 72000		# Idle time out in seconds used when in MMU pause state
disable_heater: 600		# Delay in seconds after which the hotend heater is disabled in the MMU_PAUSE state
default_extruder_temp: 220	# The baseline temperature for performing swaps and forming tips outside of a print
z_hop_height_toolchange: 0	# IN PRINT ONLY: Height in mm of z_hop move on toolchange, runout or error to avoid blob on print
z_hop_speed: 15			# Speed of z_hop move (mm/s)
auto_calibrate_gates: 0		# ADVANCED: Automated gate (not gate#0) calibration. 1=calibrated automatically on first load, 0=disabled
strict_filament_recovery: 0	# If enabled with MMU with toolhead sensor, this will cause filament position recovery to
				# perform extra moves to look for filament trapped in the space after extruder but before sensor
retry_tool_change_on_error: 0	# Whether to automatically retry a failed tool change. If enabled Happy Hare will perform
				# the equivalent of 'MMU_RECOVER' + 'Tx' commands which usually is all that is necessary
				# to recover. Note that enabling this can mask problems with your MMU
print_start_detection: 1	# ADVANCED: Enabled for Happy Hare to automatically detect start and end of print and call
				# _MMU_START_PRINT and _MMU_END_PRINT. Disable if you want to include in your own macros
encoder_move_validation: 1	# 1 = Normally Encoder validates move distances are within given tolerance (slower but more safe)
				# 0 = Validation is disabled for many moves (eliminates slight pause between moves but less safe)
gcode_load_sequence: 0		# VERY ADVANCED: Gcode loading sequence 1=enabled, 0=internal logic (default)
gcode_unload_sequence: 0	# VERY ADVANCED: Gcode unloading sequence, 1=enabled, 0=internal logic (default)


# ADVANCED: MMU macro overrides --- ONLY SET IF YOU'RE COMFORTABLE WITH KLIPPER MACROS -----------------------------------
#
# 'pause_macro' defines what macro to call on MMU error (must put printer in paused state)
# Other macros are detailed in 'mmu_sequence.cfg'
#
pause_macro: PAUSE
#pre_unload_macro: _MMU_PRE_UNLOAD		# Called before starting the unload
#post_form_tip_macro: _MMU_POST_FORM_TIP		# Called immediately after tip forming
#post_unload_macro: _MMU_POST_UNLOAD		# Called after unload completes
#pre_load_macro: _MMU_PRE_LOAD			# Called before starting the load
#post_load_macro: _MMU_POST_LOAD			# Called after the load is complete
#unload_sequence_macro: _MMU_UNLOAD_SEQUENCE	# VERY ADVANCED: Optionally called based on 'gcode_unload_sequence'
#load_sequence_macro: _MMU_LOAD_SEQUENCE		# VERY ADVANCED: Optionally called based on 'gcode_load_sequence'


# ADVANCED: See documentation for use of these ---------------------------------------------------------------------------
#
# Examples...
# Gate:                #0      #1      #2      #3      #4      #5      #6      #7      #8
#gate_material:        PLA,    ABS,    ABS,    ABS+,   PLA,    PLA,    PETG,   TPU,    ABS
#gate_color:           red,    black,  yellow, green,  blue,   indigo, ffffff, grey,   black
#gate_spool_id:        3,      2,      1,      4,      5,      6,      7,      -1,     9
#gate_status:          1,      0,      1,      2,      2,     -1,     -1,      0,      1
#gate_speed_override:  100,    100,    100,    100,    100,    100,    100,    50,     100
#endless_spool_groups: 0,      1,      2,      1,      0,      0,      3,      4,      1
#
# Tool:                T0      T1      T2      T3      T4      T5      T6      T7      T8
#tool_to_gate_map:     0,      1,      2,      3,      4,      5,      6,      7,      8


# ADVANCED/CUSTOM MMU: See documentation for use of these ----------------------------------------------------------------
#
# Normally all these settings are set based on your choice of 'mmu_vendor' and 'mmu_version', but they can be overridden.
# If you have selected a vendor of "Other" you must set these else you will get arbitary ERCFv1.1 defaults.
#
#cad_gate0_pos: 4.2			# Approximate distance from endstop to first gate. Used for rough calibration only
#cad_gate_width: 21.0			# Width of each gate
#cad_bypass_offset: 0			# Distance from limit of travel back to the bypass (ERCF v2.0)
#cad_last_gate_offset: 2.0		# Distance from limit of travel back to last gate
#cad_selector_tolerance: 10.0 		# How much extra selector movement to allow
#
#encoder_default_resolution: 0.676	# Approximate resolution(mm) of a single encoder "count". Not used for measurement

